﻿@{
    var router = ViewContext.Controller.ControllerContext.RouteData.Values;
    var pageId = router["controller"] + "_" + @router["action"] + "_";
}

<div id="@(pageId)toolbar" class="clearfix" style="height:27px; overflow:hidden;">
    <div class="pull-left" style="margin-top: 1px;">
        <input type="text" class="easyui-searchbox" name="q" placeholder="Search" style="width: 240px;"
               data-options="
                searcher: function(value, name) {
                    @(router["controller"]).@(router["action"]).$grid.datagrid('load', {
                        q: value,
                        filed: name
                    })
                },
                menu: '#@(pageId)searchtype'
            " />
        <div id="@(pageId)searchtype" style="width: 100px">
            @foreach (var p in (Model.GetType() as Type).GetProperties()
                .Where(p => p.CanRead && p.Name != "ID"))
            {
                <div data-options="name:'@p.Name'">@p.Name</div>
            }
        </div>
    </div>
    <div class="pull-right">
        <script type="text/javascript">
            $('#@(pageId)toolbar').find('.pull-right').html($('#@(pageId)toolbarExt').html());
            $('#@(pageId)toolbarExt').remove();
        </script>
    </div>
</div>
<table id="@(pageId)grid" class="easyui-datagrid" title="@(ViewBag.Title)列表" style="height: 500px; "
       data-options="
        fitColumns: false,
        striped: true,
        nowrap: true,
        idField: 'ID',
        pagination: true,
        pageSize: 50,
        rownumbers: true,
        singleSelect:true,
        toolbar: '#@(pageId)toolbar',
        url: '/Laboratory/@router["controller"]/@router["action"]Data/', method: 'POST'
    ">
    <thead>
        <tr>
            @foreach (var p in (Model.GetType() as Type).GetProperties()
                .Where(p => p.CanRead && p.Name != "ID"))
            {
                <th data-options="field:'@p.Name'">@p.Name</th>
            }
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<script type="text/javascript">
    window['@router["controller"]'] = window['@router["controller"]'] || {};
    @(router["controller"])['@router["action"]'] = {};

    @(router["controller"])['@router["action"]'].$grid = $('#@(pageId)grid');
    @(router["controller"])['@router["action"]'].$pager = @(router["controller"])['@router["action"]'].$grid.datagrid().datagrid('getPager');
</script>